package com.liang.service.Provider;

import com.liang.dao.BaseDao;
import com.liang.dao.provider.ProviderImpl;
import com.liang.pojo.Provider;

import javax.xml.crypto.Data;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class ProviderServiceImpl implements ProviderService{
    ProviderImpl providerDao = null;
    public ProviderServiceImpl() {
        providerDao= new ProviderImpl();
    }

    @Override
    public Integer getCount(String proCode, String proName) {
        Connection connection = BaseDao.getConnection();
        Integer count = 0;
        count = providerDao.getCount(connection, proCode, proName);

        return count;
    }

    @Override
    public List<Provider> getProviderList(String proCode, String proName, int pageNo, int pageSize) {
        List<Provider> list = new ArrayList<>();
        Connection connection = BaseDao.getConnection();
        list = providerDao.getProviderList(connection,proCode,proName,pageNo,pageSize);

        return list;
    }

    @Override
    public Provider getProviderView(Integer id) {
        Provider provider = new Provider();
        Connection connection = BaseDao.getConnection();
        provider = providerDao.getProviderView(connection, id);

        return provider;
    }

    @Override
    public Provider getProvideOfProCode(String proCode) {
        Provider provider = new Provider();
        Connection connection = BaseDao.getConnection();
        provider = providerDao.getProvideOfProCode(connection, proCode);

        return provider;
    }

    @Override
    public Boolean updateProvider(Integer id, String proCode, String proName, String proContact, String proPhone, String proAddress, String proFax, String proDesc,Integer modifyBy, Date modifyDate) {
        Boolean flag = false;
        Connection connection = BaseDao.getConnection();
        flag = providerDao.updateProvider(connection,id,proCode, proName, proContact, proPhone, proAddress,proFax,proDesc,modifyBy,modifyDate);

        return flag;
    }

    @Override
    public Boolean insertProvider(String proCode, String proName, String proContact, String proPhone, String proAddress, String proFax, String proDesc, Integer createdBy, Date creationDate) {
        Boolean flag = false;
        Connection connection = BaseDao.getConnection();
        flag = providerDao.insertProvider(connection,proCode, proName, proContact, proPhone, proAddress,proFax,proDesc,createdBy,creationDate);

        return flag;
    }

    @Override
    public Boolean deleteProvider(Integer id) {
        Boolean flag = false;
        Connection connection = BaseDao.getConnection();
        flag = providerDao.deleteProvider(connection, id);

        return flag;
    }
}
